package com.corpgovernment.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 前端偷懒，后端卑微
 */
public class LazyFrontUtils {

    private static final String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};

    /**
     * 获取时间的周几显示
     */
    public static String getWeekDay(String dateStr, String pattern) {
        try {
            return getWeekDay(new SimpleDateFormat(pattern).parse(dateStr));
        } catch (ParseException e) {
            return "";
        }
    }

    public static String getWeekDay(Date time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time.getTime());
        int weekday = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return weekDays[weekday];
    }
}
